package com.example.fitnessservice.api.web;

import com.example.fitnessservice.module.pojo.*;
import com.example.fitnessservice.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author:XuRui
 * @Date:2022/11/21 22:12
 */
@RestController
@RequestMapping("/coach")
public class CoachController {
    @Autowired
    private CoachService coachService;

    @GetMapping("/findAll")
    public Result findAll(){
        Result result = new Result();
        List<Coach> coaches = coachService.findAll();
        if(coaches!=null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(coaches);
        }else{
            result.setCode(500);
            result.setMsg("查询失败");
        }

        return result;
    }

    @GetMapping("/findAll1")
    public Result findAll1(){
        Result result = new Result();
        List<Coach> coaches = coachService.findAll1();
        if(coaches!=null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(coaches);
        }else{
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @GetMapping("/findWalletByCid/{cid}")
    public Result findWalletByCid(@PathVariable Integer cid){
        Result result = new Result();
        Integer money = coachService.findWalletByCid(cid);
        result.setData(money);
        return result;
    }

    @GetMapping("/findClassByCid/{cid}")
    public Result findClassByCid(@PathVariable Integer cid){
        Result result = new Result();
        List<CourseDetails> courseDetails = coachService.findClassByCid(cid);
        if(courseDetails!=null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(courseDetails);
        }else{
            result.setCode(500);
            result.setMsg("查询失败");
        }

        return result;
    }

    @GetMapping("/findOldOrderByCid/{cid}")
    public Result findOldOrderByCid(@PathVariable Integer cid){
        Result result = new Result();
        List<CourseOrderDetails> courseOrderDetails = coachService.findOldOrderByCid(cid);
        if(courseOrderDetails!=null){
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(courseOrderDetails);
        }else{
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @GetMapping("/findNewOrderByCid/{cid}")
    public Result findNewOrderByCid(@PathVariable Integer cid){
        Result result = new Result();
        List<CourseOrderDetails> newOrderByCid = coachService.findNewOrderByCid(cid);
        if (newOrderByCid != null) {
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(newOrderByCid);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @GetMapping("/findCourseOrderDetails/{cid}")
    public Result findCourseOrderDetails(@PathVariable Integer cid){
        Result result = new Result();
        String str= coachService.findCourseOrderDetails(cid);
        result.setData(str);
        return result;
    }

    @GetMapping("/findCoachBookingByCid/{cid}")
    public Result findCoachBookingByCid(@PathVariable Integer cid) {
        Result result = new Result();
        List<CoachBooking> coachBookingByCid = coachService.findCoachBookingByCid(cid);
        if (coachBookingByCid != null) {
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(coachBookingByCid);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }

    @GetMapping("/findCourseDetails")
    public Result findCourseDetails() {
        Result result = new Result();
        List<CourseDetails> courseDetails = coachService.findCourseDetails();
        if (courseDetails != null) {
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(courseDetails);
        } else {
            result.setCode(500);
            result.setMsg("查询失败");
        }
        return result;
    }
}
